package com.hksj.cm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.cm.dto.DeviceAlarmDTO;
import com.hksj.cm.service.DeviceAlarmService;
import com.hksj.cm.vo.DeviceAlarmRankVO;
import com.hksj.cm.vo.DeviceAlarmVO;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName DeviceAlarmController
 * @Description TODO
 * @Author @陈章
 * @Date 2024/7/30 10:01
 * @Version 1.0
 */
@Api(tags = "洁净度设备告警")
@RestController
@RequestMapping("/api/deviceAlarm")
public class DeviceAlarmController {

    @Autowired
    private DeviceAlarmService service;

    @ApiOperation(value = "查询设备历史告警历史记录")
    @PostMapping("/deviceAlarmList")
    public Rest<Page<DeviceAlarmVO>> deviceAlarmList(@RequestBody DeviceAlarmDTO dto) {
        Page<DeviceAlarmVO> page = service.deviceAlarmList(dto);
        return Rest.ok(page);
    }

    @ApiOperation(value = "查询设备报警次数")
    @PostMapping("/deviceAlarmCount")
    public Rest<Integer> deviceAlarmCount(@RequestBody DeviceAlarmDTO dto) {
        int count = service.deviceAlarmCount(dto);
        return Rest.ok(count);
    }

    @ApiOperation(value = "查询设备报警排名")
    @PostMapping("/deviceAlarmRank")
    public Rest<List<DeviceAlarmRankVO>> deviceAlarmRank(@RequestBody DeviceAlarmDTO dto) {
        List<DeviceAlarmRankVO> list = service.deviceAlarmRank(dto);
        return Rest.ok(list);
    }

    @ApiOperation(value = "导出洁净度报警记录")
    @PostMapping("/exportAlarm")
    public void exportAlarm(@RequestBody DeviceAlarmDTO dto, HttpServletResponse response) {
        service.exportAlarm(dto, response);
    }

}
